home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / Crystal / 3rdparty / JavaVM / Plug-in / jplugin.exe / jaws.jar / sun / beanbox / simpleresource / SimpleResourceConnection.class (.txt) < prev   
Encoding:
Java Class File  |  1998-06-22  |  2.4 KB  |  71 lines

  1. package sun.beanbox.simpleresource;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import sun.beanbox.SimpleClassLoader;
  9.  
  10. public class SimpleResourceConnection extends URLConnection {
  11.    private static boolean debug;
  12.    private Object resource;
  13.    private String cookie;
  14.    private String name;
  15.    private final String prefix = "SIMPLE";
  16.    private final int prefixLength = "SIMPLE".length();
  17.  
  18.    protected SimpleResourceConnection(URL var1) throws MalformedURLException, IOException {
  19.       super(var1);
  20.       this.debug("SimpleResourceConnection(" + var1 + ")");
  21.       String var2 = var1.getFile();
  22.       if (var2.startsWith("/")) {
  23.          var2 = var2.substring(1);
  24.       }
  25.  
  26.       if (!var2.startsWith("SIMPLE")) {
  27.          throw new MalformedURLException("SimpleResource file should start with /SIMPLE");
  28.       } else {
  29.          this.cookie = var2.substring(this.prefixLength, var2.indexOf("/+/"));
  30.          this.name = var2.substring(var2.indexOf("/+/") + 3);
  31.          this.debug(" cookie: " + this.cookie);
  32.          this.debug(" name: " + this.name);
  33.       }
  34.    }
  35.  
  36.    public void connect() throws IOException {
  37.       this.debug("Looking for " + this.cookie + ", " + this.name + " in SimpleResourceLoader");
  38.       Object var1 = SimpleClassLoader.getLocalResource(this.cookie, this.name);
  39.       if (var1 == null) {
  40.          this.debug("Invalid resource name");
  41.          this.resource = null;
  42.       } else {
  43.          this.debug("Found resource " + var1);
  44.          this.resource = var1;
  45.       }
  46.    }
  47.  
  48.    public Object getContent() throws IOException {
  49.       if (!super.connected) {
  50.          this.connect();
  51.       }
  52.  
  53.       return this.resource;
  54.    }
  55.  
  56.    public InputStream getInputStream() throws IOException {
  57.       if (!super.connected) {
  58.          this.connect();
  59.       }
  60.  
  61.       return this.resource instanceof InputStream ? (InputStream)this.resource : SimpleClassLoader.getLocalResourceAsStream(this.cookie, this.name);
  62.    }
  63.  
  64.    private void debug(String var1) {
  65.       if (debug) {
  66.          System.err.println(var1);
  67.       }
  68.  
  69.    }
  70. }
  71.